<?=$this->headTitle('Настройки');?>
<?php $this->headLink()->appendStylesheet('/twitterbootstrap/css/bootstrap.min.css')?>
<?= $this->headLink() ?>
<script type="text/javascript">
    $(function(){

        $('input').live('change', function(){
            var inpV = $(this).val();
            $(this).attr('value',inpV);
        });

        $('#changelogin').click(function(){
            inputInit($(this));
        });
        $('#changename').click(function(){
            inputInit($(this));
        });
        $('#changeemail').click(function(){
            inputInit($(this));
        });
        $('#changepass').click(function(){
            inputInit($(this));
        });
    });
function inputInit(data){
    var parTr,log,inp,btnS,btnC,ico;
        parTr = $(data).parent().parent();
        log = parTr.find('span').text();
        if(parTr.find('input').length > 0){ parTr.find('input:last').remove();}
        inp = $('<input>',{type:'text','style':'margin:0;padding:5px;size:15;border:1px solid #555555;border-radius:2px;',value:log});
        btnS = $('<button>',{id:'savebtn',text:'Сохранить','class':'btn btn-success',style:'margin-left:5px'}).bind('click',saveData).bind('hover',function(){$(this).focus();});
        btnC = $('<button>',{id:'cnlbtn',text:'Отмена','class':'btn btn-warning',style:'margin-left:5px'}).bind('click',cancelEdit);
        ico = $('<i>');
        parTr.find('span').hide();
        parTr.find('td:nth-child(2)').append(inp);
        $(data).hide();
        parTr.find('td:last').append(btnS,btnC);

}
    function saveData(e){
       var parTr = $(e.target).parent().parent();
       var inpV = $(e.target).parent().parent().find('input');

        $.post('/admin/index/settings',{oper:'update','id':$('#edit tbody tr:first').data('id'),'target':parTr.attr('id'),data:inpV.val()},function(resp){
            if(resp.oper === 'success'){

                parTr.find('span').text(resp.data);
                parTr.find('input').val(resp.data);
                cancelEdit(e);
            }else{
                cancelEdit(e);
            }
        });
    }
    function cancelEdit(e){
       var parTr = $(e.target).parent().parent();
        parTr.find('button,input').hide();
        parTr.find('span').show();
        parTr.find('button').not('#savebtn,#cnlbtn').show();

    }
</script>
<?php if(isset($this->notice)):?>
    <div class="alert alert-error" style="margin-left:300px;margin-top:30px;width:600px;"><?=$this->notice?></div>
<?php else:?>
<div id="edit" style="float:left;">

    <table class="table">
    <thead>
    <tr class="success">
         <th colspan="3"><p class="text text-error">Редактирование персональных данных</p></th>
    </tr>
    </thead>
    <tbody>

    <tr id ="userlogin" class="info" data-id="<?= $this->data['id']?>">
        <td><p class="text text-info">Логин</p></td><td width="250"><span><?= $this->data['userlogin']?></span></td><td width="200"><button id="changelogin" class="btn btn-primary"><i class="icon-pencil icon-white"></i> Изменить логин</button></td>
    </tr>
    <tr id="username" class="info">
        <td><p class="text text-info">Имя</p></td><td><span><?= $this->data['username']?></span></td><td width="200"><button id="changename" class="btn btn-primary"><i class="icon-pencil icon-white"></i> Изменить имя</button></td>
    </tr>
    <tr id="email" class="info">
        <td><p class="text text-info">Email</p></td><td><span><?= $this->data['email']?></span></td><td width="200"><button id="changeemail" class="btn btn-primary"><i class="icon-pencil icon-white"></i> Изменить email</button></td>
    </tr>
    <tr id="password" class="info">
        <td><p class="text text-info">Пароль</p></td><td><span>**********</span></td><td width="200"><button id="changepass" class="btn btn-primary"><i class="icon-pencil icon-white"></i> Изменить пароль</button></td>
    </tr>

    </tbody>
 </table>
<?endif;?>
</div>